% trl.sty  ver 1.4    02-Mar-1999   Donald Arseneau   asnd@triumf.ca
% Copyright 1996-1999 Donald Arseneau,  Vancouver, Canada.
% This program can be used, distributed, and modified under the terms
% of the LaTeX Project Public License.
%
% A form of \verb that allows linebreaks at certain characters or
% combinations of characters, accepts reconfiguration, and can usually
% be used in the argument to another command.  It is intended for email
% addresses, hypertext links, directories/paths, etc., which normally
% have no spaces.  The font may be selected using the \trlstyle command,
% and new trl-like commands can be defined using \trldef.
%
% Usage:    Conditions:
% \trl{ }   If the argument contains any "%", "#", or "^^", or ends with
%           "\", it can't be used in the argument to another command.
%           The argument must not contain unbalanced braces.
% \trl|  |  ...where "|" is any character not used in the argument and not
%           "{" or a space.  The same restrictions as above except that the
%           argument may contain unbalanced braces.
% \xyz      for "\xyz" a defined-trl;  this can be used anywhere, no matter
%           what characters it contains.
%
% See further instructions after "\endinput"
%
\def\Trl@ttdo{% style assignments for tt fonts or T1 encoding
\def\TrlBreaks{\do\.\do\@\do\\\do\/\do\!\do\_\do\|\do\%\do\;\do\>\do\*\do\]%
 \do\)\do\,\do\?\do\'\do\+\do\A\do\B\do\C\do\D\do\E\do\F\do\G\do\H\do\I\do\J\do\K\do\L\do\M\do\N\do\O\do\P\do\Q\do\R\do\S\do\T\do\U\do\V\do\W\do\Y\do\Z\do=}%
\def\TrlBigBreaks{\do\:\do@trl@hyp}%
\def\TrlNoBreaks{\do\(\do\[\do\{\do\<}% (unnecessary)
\def\TrlSpecials{\do\ {\ }}%
\def\TrlOrds{\do\*\do\-\do\~}% any ordinary characters that aren't usually
}
\def\Trl@do{% style assignments for OT1 fonts except tt
\def\TrlBreaks{\do\.\do\@\do\/\do\!\do\%\do\;\do\]\do\)\do\,\do\?\do\+\do\=}%
\def\TrlBigBreaks{\do\:\do@trl@hyp}%
\def\TrlNoBreaks{\do\(\do\[\do\{}% prevents breaks after *next* character
\def\TrlSpecials{\do\<{\langle}\do\>{\mathbin{\rangle}}\do\_{\_%
 \penalty\@m}\do\|{\mid}\do\{{\lbrace}\do\}{\mathbin{\rbrace}}\do
 \\{\mathbin{\backslash}}\do\~{\raise.6ex\hbox{\m@th$\scriptstyle\sim$}}\do
 \ {\ }}%
\def\TrlOrds{\do\'\do\"\do\-}%
}
\def\trl@ttstyle{%
\@ifundefined{selectfont}{\def\TrlFont{\tt}}{\def\TrlFont{\ttfamily}}\Trl@ttdo
}
\def\trl@rmstyle{%
\@ifundefined{selectfont}{\def\TrlFont{\rm}}{\def\TrlFont{\rmfamily}}\Trl@do
}
\def\trl@sfstyle{%
\@ifundefined{selectfont}{\def\TrlFont{\sf}}{\def\TrlFont{\sffamily}}\Trl@do
}
\def\trl@samestyle{\ifdim\fontdimen\thr@@\font=\z@ \trl@ttstyle \else
  \trl@rmstyle \fi \def\TrlFont{}}

\@ifundefined{strip@prefix}{\def\strip@prefix#1>{}}{}
\@ifundefined{verbatim@nolig@list}{\def\verbatim@nolig@list{\do\`}}{}

\def\Trl{%
 \begingroup \let\trl@moving\relax\relax \endgroup
 \ifmmode\@nomatherr$\fi
 \TrlFont $\fam\z@ \textfont\z@\font
 \let\do\@makeother \dospecials % verbatim catcodes
 \catcode`{\@ne \catcode`}\tw@ \catcode`\ 10 % except braces and spaces
 \medmuskip0mu \thickmuskip\medmuskip \thinmuskip\medmuskip
 \@tempcnta\fam\multiply\@tempcnta\@cclvi
 \let\do\set@mathcode \TrlOrds % ordinary characters that were special
 \advance\@tempcnta 8192 \TrlBreaks % bin
 \advance\@tempcnta 4096 \TrlBigBreaks % rel
 \advance\@tempcnta 4096 \TrlNoBreaks % open
 \let\do\set@mathact \TrlSpecials % active
 \let\do\set@mathnolig \verbatim@nolig@list % prevent ligatures
 \@ifnextchar\bgroup\Trl@z\Trl@y}

\def\Trl@y#1{\catcode`{11 \catcode`}11
  \def\@tempa##1#1{\Trl@z{##1}}\@tempa}
\def\Trl@z#1{\def\@tempa{#1}\expandafter\expandafter\expandafter\Trl@Hook
  \expandafter\strip@prefix\meaning\@tempa\TrlRight\m@th$\endgroup}
\def\Trl@Hook{\TrlLeft}
\let\TrlRight\@empty
\let\TrlLeft\@empty

\def\set@mathcode#1{\count@`#1\advance\count@\@tempcnta\mathcode`#1\count@}
\def\set@mathact#1#2{\mathcode`#132768 \lccode`\~`#1\lowercase{\def~{#2}}}
\def\set@mathnolig#1{\ifnum\mathcode`#1<32768
   \lccode`\~`#1\lowercase{\edef~{\mathchar\number\mathcode`#1_{\/}}}%
   \mathcode`#132768 \fi}

\def\trldef#1#2{\begingroup \setbox\z@\hbox\bgroup
  \def\Trl@z{\Trl@def{#1}{#2}}#2}
\expandafter\ifx\csname DeclareRobustCommand\endcsname\relax
  \def\Trl@def#1#2#3{\m@th$\endgroup\egroup\endgroup
    \def#1{#2{#3}}}
\else
  \def\Trl@def#1#2#3{\m@th$\endgroup\egroup\endgroup
    \DeclareRobustCommand{#1}{#2{#3}}}
\fi

\def\trlstyle#1{\csname trl@#1style\endcsname}

% Sample (and default) configuration:
%
\newcommand\trl{\begingroup \Trl}
%
% picTeX defines \path, so declare it optionally:
\@ifundefined{path}{\newcommand\path{\begingroup \trlstyle{tt}\Trl}}{}
%
% too many styles define \email like \address, so I will not define it.
% \newcommand\email{\begingroup \trlstyle{rm}\Trl}

% Process LaTeX \package options
%
\trlstyle{tt}
\let\Trl@sppen\@M
\def\do@trl@hyp{}% by default, no breaks after hyphens

\@ifundefined{ProvidesPackage}{}{
  \ProvidesPackage{trl}[1999/03/02 \space ver 1.4 \space
       Verb mode for trls, email addresses, and file names]
  \DeclareOption{hyphens}{\def\do@trl@hyp{\do\-}}% allow breaks after hyphens
  \DeclareOption{obeyspaces}{\let\Trl@Hook\relax}% a flag for later
  \DeclareOption{spaces}{\let\Trl@sppen\relpenalty}
  \DeclareOption{T1}{\let\Trl@do\Trl@ttdo}
  \ProcessOptions
\ifx\Trl@Hook\relax % [obeyspaces] was declared
  \def\Trl@Hook#1\TrlRight\m@th{\edef\@tempa{\noexpand\TrlLeft
    \Trl@retain#1\Trl@nosp\, }\@tempa\TrlRight\m@th}
  \def\Trl@retain#1 {#1\penalty\Trl@sppen\ \Trl@retain}
  \def\Trl@nosp\,#1\Trl@retain{}
\fi
}

\edef\trl@moving{\csname Trl Error\endcsname}
\expandafter\edef\trl@moving
 {\csname trl used in a moving argument.\endcsname}
\expandafter\expandafter\expandafter \let \trl@moving\undefined 

\endinput
%
% trl.sty  ver 1.4   02-Mar-1999   Donald Arseneau   asnd@reg.triumf.ca
%
% This package defines "\trl", a form of "\verb" that allows linebreaks,
% and can often be used in the argument to another command.  It can be
% configured to print in different formats, and is particularly useful for
% hypertext links, email addresses, directories/paths, etc.  The font may
% be selected using the "\trlstyle" command and pre-defined text can be
% stored with the "\trldef" command. New trl-like commands can be defined,
% and a "\path" command is provided this way.
%
% Usage:    Conditions:
% \trl{ }   If the argument contains any "%", "#", or "^^", or ends with
%           "\", it can't be used in the argument to another command.
%           The argument must not contain unbalanced braces.
% \trl|  |  ...where "|" is any character not used in the argument and not
%           "{" or a space.  The same restrictions as above except that the
%           argument may contain unbalanced braces.
% \xyz      for "\xyz" a defined-trl;  this can be used anywhere, no matter
%           what characters it contains.
%
% The "\trl" command is fragile, and its argument is likely to be very
% fragile, but a defined-trl is robust.
%
% Package Option:  obeyspaces
% Ordinarily, all spaces are ignored in the trl-text.  The "[obeyspaces]"
% option allows spaces, but may introduce spurious spaces when a trl
% containing "\" characters is given in the argument to another command.
% So if you need to obey spaces you can say "\usepackage[obeyspaces]{trl}",
% and if you need both spaces and backslashes, use a `defined-trl' for
% anything with "\".
%
% Package Option:  hyphens
% Ordinarily, breaks are not allowed after "-" characters because this
% leads to confusion. (Is the "-" part of the address or just a hyphen?)
% The package option "[hyphens]" allows breaks after explicit hyphen
% characters.  The "\trl" command will *never ever* hyphenate words.
%
% Package Option:  spaces
% Likewise, breaks are not usually allowed after spaces under the
% "[obeyspaces]" option, but giving the options "[obeyspaces,spaces]"
% will allow breaks at those spaces.
%
% Package Option:  T1
% This signifies that you will be using T1-encoded fonts which contain
% some characters missing from most older (OT1) encoded TeX fonts.  This
% changes the default definition for "\trlstyle{rm}".
%
% Defining a defined-trl:
% Take for example the email address "myself%node@gateway.net" which could
% not be given (using "\trl" or "\verb") in a caption or parbox due to the
% percent sign.  This address can be predefined with
%    \trldef{\myself}\trl{myself%node@gateway.net}   or
%    \trldef{\myself}\trl|myself%node@gateway.net|
% and then you may use "\myself" instead of "\trl{myself%node@gateway.net}"
% in an argument, and even in a moving argument like a caption because a
% defined-trl is robust.
%
% Style:
% You can switch the style of printing using "\trlstyle{tt}", where "tt"
% can be any defined style.  The pre-defined styles are "tt", "rm", "sf",
% and "same" which all allow the same linebreaks but different fonts --
% the first three select a specific font and the "same" style uses the
% current text font.  You can define your own styles with different fonts
% and/or line-breaking by following the explanations below.  The "\trl"
% command follows whatever the currently-set style dictates.
%
% Alternate commands:
% It may be desireable to have different things treated differently, each
% in a predefined style; e.g., if you want directory paths to always be
% in tt and email addresses to be rm, then you would define new trl-like
% commands as follows:
%
%    \newcommand\email{\begingroup \trlstyle{rm}\Trl}
%    \newcommand\directory{\begingroup \trlstyle{tt}\Trl}
%
% You must follow this format closely, and NOTE that the final command is
% "\Trl", not "\trl".  In fact, the "\directory" example is exactly the
% "\path" definition which is pre-defined in the package.  If you look
% above, you will see that "\trl" is defined with
%    \newcommand\trl{\begingroup \Trl}
% I.e., using whatever trl-style has been selected.
%
% You can make a defined-trl for these other styles, using the usual
% "\trldef" command as in this example:
%
%    \trldef{\myself}{\email}{myself%node.domain@gateway.net}
%
% which makes "\myself" act like "\email{myself%node.domain@gateway.net}",
% if the "\email" command is defined as above.  The "\myself" command
% would then be robust.
%
% Defining styles:
% Before describing how to customize the printing style, it is best to
% mention something about the unusual implementation of "\trl".  Although
% the material is textual in nature, and the font specification required
% is a text-font command, the text is actually typeset in *math* mode.
% This allows the context-sensitive linebreaking, but also accounts for
% the default behavior of ignoring spaces.  Now on to defining styles.
%
% To change the font or the list of characters that allow linebreaks, you
% could redefine the commands "\TrlFont", "\TrlBreaks", "\TrlSpecials" etc.
% directly in the document, but it is better to define a new `trl-style'
% (following the example of "\trl@ttstyle" and "\trl@rmstyle") which defines
% all of "\TrlBigbreaks", "\TrlNoBreaks", "\TrlBreaks", "\TrlSpecials", and
% "\TrlFont".
%
% Changing font:
% The "\TrlFont" command selects the font.  The definition of "\TrlFont"
% done by the pre-defined styles varies to cope with a variety of LaTeX
% font selection schemes, but it could be as simple as "\def\TrlFont{\tt}".
% Depending on the font selected, some characters may need to be defined
% in the "\TrlSpecials" list because many fonts don't contain all the
% standard input characters.
%
% Changing linebreaks:
% The list of characters that allow line-breaks is given by "\TrlBreaks"
% and "\TrlBigBreaks", which have the format "\do\c" for character "c".
% The differences are that `BigBreaks' have a lower penalty and have
% different breakpoints when in sequence (as in "http://"): `BigBreaks'
% are treated as mathrels while `Breaks' are mathbins (see The TeXbook,
% p.170). In particular, a series of `BigBreak' characters will break at
% the end and only at the end; a series of `Break' characters will break
% after the first and after every following *pair*; there will be no
% break after a `Break' character if a `BigBreak' follows.  In the case
% of "http://" it doesn't matter whether ":" is a `Break' or `BigBreak' --
% the breaks are the same in either case; but for DECnet nodes with "::"
% it is important to prevent breaks *between* the colons, and that is why
% colons are `BigBreaks'.
%
% It is possible for characters to prevent breaks after the next following
% character (I use this for parentheses).  Specify these in "\TrlNoBreaks".
%
% You can do arbitrarily complex things with characters by making them
% active in math mode (mathcode hex-8000) and specifying the definition(s)
% in "\TrlSpecials".  This is used in the rm and sf styles for OT1 font
% encoding to handle several characters that are not present in those
% computer-modern style fonts.  See the definition of "\Trl@do", which
% is used by both "\trl@rmstyle" and "\trl@sfstyle"; it handles missing
% characters via "\TrlSpecials".  The nominal format for setting each
% special character "c" is: "\do\c{<definition>}", but you can include
% other definitions too.
%
%
% If all this sounds confusing ... well, it is!  But I hope you won't need
% to redefine breakpoints -- the default assignments seem to work well for
% a wide variety of applications.  If you do need to make changes, you can
% test for breakpoints using regular math mode and the characters "+=(a".
%
% Yet more flexibility:
% You can also customize the verbatim text by defining "\TrlRight" and/or
% "\TrlLeft", e.g., for ISO formatting of trls surrounded by "<  >", define
%
%    \renewcommand\trl{\begingroup \def\TrlLeft{<trl: }\def\TrlRight{>}%
%        \trlstyle{tt}\Trl}
%
% The meanings of "\TrlLeft" and "\TrlRight" are *not* reproduced verbatim.
% This lets you use formatting commands there, but you must be careful not
% to use TeX's special characters ("\^_%~#$&{}" etc.) improperly.
% You can also define "\TrlLeft" to reprocess the verbatim text, but the
% format of the definition is special:
%
%    \def\TrlLeft#1\TrlRight{ ... do things with #1 ... }
%
% Yes, that is "#1" followed by "\TrlRight" then the definition.  For
% example, to put a hyperTeX hypertext link in the DVI file:
%
%    \def\TrlLeft#1\TrlRight{\special{html:<a href="#1">}#1\special{html:</a>}}
%
% Using this technique, trl.sty can provide a convenient interface for
% performing various operations on verbatim text.  You don't even need
% to print out the argument!  For greatest efficiency in such obscure
% applications, you can define a null trl-style where all the lists like
% "\TrlBreaks" are empty.
%
% Revision History:
% ver 1.1 6-Feb-1996: 
% Fix hyphens that wouldn't break and ligatures that weren't suppressed.
% ver 1.2 19-Oct-1996:
% Package option for T1 encoding; Hooks: "\TrlLeft" and "\TrlRight".
% ver 1.3 21-Jul-1997:
% Prohibit spaces as delimiter characters; change ascii tilde in OT1.
% ver 1.4 02-Mar-1999
% LaTeX license; moving-argument-error
% The End

Test file integrity:  ASCII 32-57, 58-126:  !"#$%&'()*+,-./0123456789
:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
